/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ventanas;

import java.util.Iterator;
import javax.swing.DefaultListModel;
import negocio.Complejo;
import negocio.Evento;
import negocio.Fila;
import negocio.Funcion;
import negocio.Sala;
import negocio.Seccion;
import negocio.Tarifa;

/**
 *
 * @author diego
 */
public class FrmTarifas extends javax.swing.JDialog {
    private Complejo unComplejo;
    private Funcion unaFuncion;
    private Sala unaSala;
    private Seccion unaSeccion;
    private Fila unaFila;
    
    private Tarifa unaTarifa;
    private Evento unEvento;
    
    DefaultListModel modelFunciones = new DefaultListModel();
    DefaultListModel modelSalas = new DefaultListModel();
    DefaultListModel modelSecciones = new DefaultListModel();
    DefaultListModel modelFilas = new DefaultListModel();
    DefaultListModel modelEventos = new DefaultListModel();
    DefaultListModel modelTarifas = new DefaultListModel();
        
   
    /**
     * Creates new form Tarifas
     */
    public FrmTarifas(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    
    public FrmTarifas(MainFrame formPadre,boolean modal,Complejo unComplejo){
        initComponents();
        this.unComplejo = unComplejo;
        this.inicializar();
    }
    
    public void inicializar() {
        this.cargarEventos();        
    }
    
    public void cargarEventos(){
        if(this.unComplejo.obtenerEventos().size() > 0){
            Iterator it = this.unComplejo.obtenerEventos().iterator();
            while(it.hasNext()){
                Evento unEvento = (Evento) it.next();
                this.modelEventos.addElement(unEvento);
            }
           // unEvento = null;
        }else{
            this.modelEventos.addElement("No se encontraron eventos habilitados");
        }
    }
    
    public void guardarEvento(){
        //this.unUsuario = (Usuario) this.modelUsuarios.getElementAt(this.lstUsuarios.getSelectedIndex());
        this.unEvento = (Evento) this.modelEventos.getElementAt(this.lstEventos.getSelectedIndex());
    }
    
    public void cargarFunciones(){
        if(this.unEvento.obtenerFunciones().size() > 0){
            Iterator it = this.unEvento.obtenerFunciones().iterator();
            while(it.hasNext()){
                Funcion unaFuncion = (Funcion) it.next();
                this.modelFunciones.addElement(unaFuncion);
            }
            
            
        }else{
            this.modelFunciones.addElement("No se encontraron funciones habilitadas");
        }
    }
    
    public void guardarSala(){
        this.unaSala = (Sala) this.modelSalas.getElementAt(this.lstSalas.getSelectedIndex());
    }
    
    public void cargarSecciones(){
     if(this.unaSala.ObtenerSecciones().size() > 0){
         Iterator it = this.unaSala.ObtenerSecciones().iterator();
         while(it.hasNext()){
             Seccion unaSeccion = (Seccion) it.next();
             this.modelSecciones.addElement(unaSeccion);             
         }
     }else{
         this.modelSecciones.addElement("No se Encontraron Secciones.");
     }   
    }
    public void guardarSeccion(){
        this.unaSeccion = (Seccion) this.modelSecciones.getElementAt(this.lstSecciones.getSelectedIndex());
    }
    
    public void cargarFilas(){
        if(this.unaSeccion.obtenerFilas().size() > 0){
            Iterator it = this.unaSeccion.obtenerFilas().iterator();
            while(it.hasNext()){
                Fila unaFila = (Fila) it.next();
                this.modelFilas.addElement(unaFila);
            }
        }else{
            this.modelFilas.addElement("No se encontraron Filas");
        }
        
    }
    public void guardarTarifa(){
        Tarifa unaTarifa;
        if(this.unaFila != null && this.unaFuncion != null){
            Double precio = Double.parseDouble(this.txtPrecio.getText());
            unaTarifa = new Tarifa (this.unaFila,this.unaFuncion,precio);
            this.unaFuncion.agregarTarifa(unaTarifa);
        }
    }
    
    public void guardarFuncion(){
        this.unaFuncion = (Funcion) this.modelFunciones.getElementAt(this.lstFunciones.getSelectedIndex());
    }
    
    public void cargarTarifas(){
        if(this.unaFuncion.getTarifas().size() > 0){
            Iterator it = this.unaFuncion.getTarifas().iterator();
            while(it.hasNext()){
                Tarifa unaTarifa = (Tarifa) it.next();
                this.modelTarifas.addElement(unaTarifa);
            }
        }else{
            this.modelTarifas.addElement("No se encontraron tarifas");
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstFunciones = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        lstSalas = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        lstSecciones = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        lstFilas = new javax.swing.JList();
        jLabel5 = new javax.swing.JLabel();
        txtPrecio = new javax.swing.JTextField();
        btnGuardar = new javax.swing.JButton();
        btnAcepar = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        lstEventos = new javax.swing.JList();
        jScrollPane6 = new javax.swing.JScrollPane();
        lstTarifas = new javax.swing.JList();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Funcion");

        lstFunciones.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstFunciones.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstFuncionesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(lstFunciones);

        jLabel2.setText("Sala");

        lstSalas.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstSalas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstSalasMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(lstSalas);

        jLabel3.setText("Seccion");

        lstSecciones.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstSecciones.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstSeccionesMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(lstSecciones);

        jLabel4.setText("Fila");

        lstFilas.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane4.setViewportView(lstFilas);

        jLabel5.setText("Precio Butaca");

        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnAcepar.setText("Aceptar");

        jLabel6.setText("Evento");

        lstEventos.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstEventos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstEventosMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(lstEventos);

        lstTarifas.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane6.setViewportView(lstTarifas);

        jLabel7.setText("Funciones");

        jLabel8.setText("Tarifas");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnAcepar))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(84, 84, 84)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel4)
                                        .addGap(0, 0, Short.MAX_VALUE))))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel7))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel1))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jScrollPane6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                .addComponent(jLabel5)
                                                .addGap(32, 32, 32)
                                                .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(btnGuardar, javax.swing.GroupLayout.Alignment.TRAILING))))))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(156, 156, 156)
                        .addComponent(btnGuardar))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane5)
                            .addComponent(jScrollPane1)
                            .addComponent(jScrollPane6))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnAcepar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void lstEventosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstEventosMouseClicked
        // TODO add your handling code here:
        this.guardarEvento();
        this.cargarFunciones();
    }//GEN-LAST:event_lstEventosMouseClicked

    private void lstSalasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstSalasMouseClicked
        // TODO add your handling code here:
        this.guardarSala();
        this.cargarSecciones();
    }//GEN-LAST:event_lstSalasMouseClicked

    private void lstSeccionesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstSeccionesMouseClicked
        // TODO add your handling code here:
        this.guardarSeccion();
        this.cargarFilas();
        
    }//GEN-LAST:event_lstSeccionesMouseClicked

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        this.guardarTarifa();
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void lstFuncionesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstFuncionesMouseClicked
        // TODO add your handling code here:
        this.guardarFuncion();
        this.cargarTarifas();
    }//GEN-LAST:event_lstFuncionesMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main2(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmTarifas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmTarifas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmTarifas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmTarifas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FrmTarifas dialog = new FrmTarifas(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAcepar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JList lstEventos;
    private javax.swing.JList lstFilas;
    private javax.swing.JList lstFunciones;
    private javax.swing.JList lstSalas;
    private javax.swing.JList lstSecciones;
    private javax.swing.JList lstTarifas;
    private javax.swing.JTextField txtPrecio;
    // End of variables declaration//GEN-END:variables
}
